package elitech.vietnam.myfashion.extend;

import java.util.List;

import com.koushikdutta.urlimageviewhelper.UrlImageViewHelper;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import elitech.vietnam.myfashion.MainActivity;
import elitech.vietnam.myfashion.R;
import elitech.vietnam.myfashion.config.Const;
import elitech.vietnam.myfashion.entites.Product;
import elitech.vietnam.myfashion.view.RecommendView;

public class RecommendAdapter extends ArrayAdapter<Product> {
	private MainActivity mContext;
	
	public RecommendAdapter(MainActivity context, int resource,
			List<Product> objects) {
		super(context, resource, objects);
		mContext = context;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {	
		View row = convertView;
		ViewHolder holder = null;
		Product mProduct = getItem(position);
		
		if (row == null) {
			LayoutInflater inflater = LayoutInflater.from(mContext);
			row = inflater.inflate(R.layout.item_recommend, parent, false);
			
			holder = new ViewHolder();
			
			holder.mImage = (ImageView) row.findViewById(R.id.recommend_img);
			holder.mTxtName = (TextView) row.findViewById(R.id.recommend_txtName);
			
			row.setTag(holder);
		} else
			holder = (ViewHolder) row.getTag();
		
		UrlImageViewHelper.setUrlDrawable(holder.mImage, Const.SERVER_IMAGE_URL
				+ mProduct.Image, R.drawable.loading300);
		
		holder.mTxtName.setText(mProduct.Name + "");
		return row;
	}
	
	static class ViewHolder {
		private ImageView mImage;
		private TextView mTxtName;
	}
}
